﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Communication.Net.Web;
using UtilZ.Dotnet.Ex.Model;

namespace UtilZ.Tool.HostPluginBase
{
    /// <summary>
    /// Websocket发送消息事件参数
    /// </summary>
    public class WebsocketSendMessageArgs : EventArgs
    {
        /// <summary>
        /// 插件标识ID
        /// </summary>
        public string PluginID { get; private set; }

        /// <summary>
        /// 发送目录,如果集合为空或null,则发送给插件标识对应的所有客户端
        /// </summary>
        public IEnumerable<WebSocketClient> Targets { get; private set; }

        /// <summary>
        ///消息类型
        /// </summary>
        public WebSocketMessageTypes MessageType { get; private set; }

        /// <summary>
        /// 消息文本
        /// </summary>
        public string Text { get; private set; }

        /// <summary>
        /// 二进制数据
        /// </summary>
        public DataSpan<byte> Data { get; private set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pluginID">插件标识ID</param>
        /// <param name="messageType">消息类型</param>
        /// <param name="targets">发送目录,如果集合为空或null,则发送给插件标识对应的所有客户端</param>
        private WebsocketSendMessageArgs(string pluginID, WebSocketMessageTypes messageType, IEnumerable<WebSocketClient> targets = null)
        {
            this.PluginID = pluginID;
            this.MessageType = messageType;
            this.Targets = targets;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pluginID">插件标识ID</param>
        /// <param name="text">消息文本</param>
        /// <param name="targets">发送目录,如果集合为空或null,则发送给插件标识对应的所有客户端</param>
        public WebsocketSendMessageArgs(string pluginID, string text, IEnumerable<WebSocketClient> targets = null)
            : this(pluginID, WebSocketMessageTypes.Text, targets)
        {
            this.Text = text;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pluginID">插件标识ID</param>
        /// <param name="data">二进制消息</param>
        /// <param name="targets">发送目录,如果集合为空或null,则发送给插件标识对应的所有客户端</param>
        public WebsocketSendMessageArgs(string pluginID, DataSpan<byte> data, IEnumerable<WebSocketClient> targets = null)
            : this(pluginID, WebSocketMessageTypes.Binary, targets)
        {
            this.Data = data;
        }
    }
}
